﻿using stdCall;
using stdCall.MyEvaluation;
using stdCall.Models;
using stdCall.TotalService;
using System;
using System.Collections;
using System.Windows.Forms;

namespace stdCall
{
    /// <summary>
    /// 主页面
    /// </summary>
    public partial class FormMain : Form
    {
        ArrayList historyStds = new ArrayList();
        static ArrayList picStars = new ArrayList();
        StudentsManager studentManager = new StudentsManager();
        UnluckyCallsManager unluckyCallsManager = new UnluckyCallsManager();
        /// <summary>
        /// 
        /// </summary>
        public FormMain()
        {
            FormMain.CheckForIllegalCrossThreadCalls = false;
            InitializeComponent();
            sendControlsToModles();
            Service.getResouseService().loadSystemResourse();
            new CourseDialog().ShowDialog();
            generateStars();
            Evaluation.picStars = picStars;
        }

        /// <summary>
        /// 让需要空间的模块获取控件
        /// </summary>
        private void sendControlsToModles()
        {
            Service.getAnimateService().addResource("label_currentStd", this.label_currentStd);
            Service.getAnimateService().addResource("label_hideCurrentStd", this.label_hideCurrentStd);
            Service.getAnimateService().addResource("label_nextStd", this.label_nextStd);
            Service.getAnimateService().addResource("label_hideNextStd", this.label_hideNextStd);
            Service.getAnimateService().addResource("panel_current", this.panel_current);
            Service.getAnimateService().addResource("panel_nextstd", this.panel_nextstd);
            Service.getEvaluateService().addResource("panel_history", this.panel_history);
        }

        /// <summary>
        /// 生成星级（黑），并加入容器
        /// </summary>
        private void generateStars()
        {
            int starSize = 52;
            int starPosX = this.label_currentStd.Width / 2 - starSize;
            int starPosY = 0;

            for (int i = 0; i < 5; i++)
            {

                System.Windows.Forms.PictureBox pictureBox_star;
                pictureBox_star = new System.Windows.Forms.PictureBox();
                pictureBox_star.Cursor = System.Windows.Forms.Cursors.Hand;
                pictureBox_star.Location = new System.Drawing.Point(starPosX, starPosY);
                pictureBox_star.Name = "pictureBox_stars";
                pictureBox_star.Size = new System.Drawing.Size(starSize, starSize);
                pictureBox_star.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
                pictureBox_star.TabIndex = 3;
                pictureBox_star.TabStop = false;
                pictureBox_star.Click += new System.EventHandler(this.pictureBox_stars_Click);
                pictureBox_star.Load("star_black.png");
                this.panel_star.Controls.Add(pictureBox_star);
                picStars.Add(pictureBox_star);
                starPosX += starSize+8;
            }
        }

        
        /// <summary>
        /// 星级初始化并随机产生倒霉鬼
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button_random_Click(object sender, EventArgs e)
        {
            clearStars();
            Service.getRandomService().startRandom();
        }
    
        /// <summary>
        /// 星星变黑，初始化
        /// </summary>
        public static void  clearStars()
        {
            foreach (PictureBox pb in picStars)
            {
                pb.Load("star_black.png");
            }
        }


        /// <summary>
        /// 星级的评价，点击可评价，不可修改
        /// </summary>
        /// <param name="sender">点击的图片</param>
        /// <param name="e"></param>
        private void pictureBox_stars_Click(object sender, EventArgs e)
        {
            Service.getEvaluateService().evaluateCurrentStd(sender);
           // clearStars();
        }

        /// <summary>
        /// 保存当前历史记录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button_save_Click(object sender, EventArgs e)
        {
            stdCall.View.DialogReply reply = new stdCall.View.DialogReply();
            if (Service.getHistoryService().saveCurrentHistory())
            {
                reply.setReply("当前历史保存成功！");
                reply.ShowDialog();
            }
            else
            {
                reply.setReply("当前历史保存失败，请检查！");
                reply.ShowDialog();
            }
        }

        /// <summary>
        /// 点击加载excel（班级名单）
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button_loadExcel_Click(object sender, EventArgs e)
        {
            stdCall.View.DialogReply reply = new stdCall.View.DialogReply();
            if (Service.getExcelService().loadExcel())
            {
                reply.setReply("班级名单导入成功！");
                reply.ShowDialog();
                //reply.Dispose();
            }
            else
            {
                reply.setReply("班级名单导入失败，请检查！");
                reply.ShowDialog();
            }
        }

 
   

    }
}
